/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package common;

import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;

public class OverlapTester {
	public static boolean overlapRectangles (Rectangle r1, Rectangle r2) {
		if (r1.x < r2.x + r2.width && r1.x + r1.width > r2.x && r1.y < r2.y + r2.height && r1.y + r1.height > r2.y)
			return true;
		else
			return false;
	}

	public static boolean pointInRectangle (Rectangle r, Vector2 p) {
		return r.x <= p.x && r.x + r.width >= p.x && r.y <= p.y && r.y + r.height >= p.y;
	}

	public static boolean pointInRectangle (Rectangle r, float x, float y) {
		
		return r.x <= x && r.x + r.width >= x && r.y <= y && r.y + r.height >= y;
	}
	
	public static boolean pointInRectangle(float xR, float yR, float width, float height, float x, float y)
	{
		return xR <= x && xR + width >= x && yR <= y && yR + height >= y;
	}
	
	 public static boolean overlapCircleRectangle(float xC, float yC, float radius, float xR, float yR, float wR, float hR) { 
	     
		 float closestX = xC; 
	     float closestY = yC; 
	        
	     if(xC < xR) { 
	         closestX = xR;  
	     }  
	     else if(xC > xR + wR) { 
	         closestX = xR + wR; 
	     } 
	        
	     if(yC < yR) { 
	         closestY = yR; 
	     }  
	     else if(yC > yR + hR) { 
	         closestY = yR + hR; 
	     } 
	      
	     return (yC <= yR) && ((((xC - closestX) * (xC - closestX)) + ((yC - closestY) * (yC - closestY))) < radius * radius);    
	        
	 }
	
}
